<template>
  <div class="content">
    <dt-search ref="search">
      <Button type="primary" v-if="unlocking('0207010901')" @click="onExport">导出</Button>
    </dt-search>

    <dt-grid ref="table" page :onFetch="onFetch" />
  </div>
</template>

<script>
  import moment from 'moment'
  import Column from './biz/Column.js'
  import SearchOpt from './biz/SearchOpt.js'
  import caseMgr from '@/biz/crimeSceneList'
  import buildMgr from '@/biz/building'
  import { buildPage } from '@/router/buildPage.js'
  import store from '@/store'
  import mgr from './biz'
  import dt from '@dt/dt'

  export default {
    data() {
      return {
        search: {}
      }
    },
    mounted() {
      this.$refs.search.init(this.$refs.table, new SearchOpt(this.search), this.search)
      this.$refs.table.init(this, new Column())
      this.$refs.table.fetch()
    },
    methods: {
      onFetch(data) {
        this.search = data
        return mgr.list(data)
      },
      onExport() {
        return mgr.exportList(this.search)
      },
      detail(row) {
        console.log(row)
        let params = {
          housesId: row.buildingId
        }
        //获取案场基本信息并保存到session
        caseMgr.buildinghousesList(params).then((res) => {
          if (res.list.length) {
            let item = { ...res.list[0] }
            // 更新案场
            buildMgr.updateBuildInfo(item)
            this.$tool.setStorage({ caseBuildingId: JSON.stringify(item.housesId) })
            store.dispatch('setRouterList', buildPage)
            // 判断案场目标达成统计跳转
            this.$router.push({
              name: 'buildingFile',
              params: {
                info: row
              }
            })
          } else {
            dt.ui.Message.warning('无该案场权限')
          }
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
  .content {
    padding: 20px;
  }
</style>
